﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ERPForms
{
    public partial class DepartamenteParametriiFrm : FrmRezumat
    {
        public DepartamenteParametriiFrm(ModuleClass mc):base(mc)
        {
            InitializeComponent();
            LunaCB.SelectedIndex = 0;
        }

        private void DepartamenteParametriiFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.exBugSetupTableAdapter.Connection = con;
            this.exBugSetupTableAdapter.Fill(this.eSRPDataSet.ExBugSetup, ModuleInfo.CodUnitate);
            this.departamenteTableAdapter.Connection = con;
            this.departamenteTableAdapter.Fill(eSRPDataSet.Departamente, ModuleInfo.CodUnitate);
            


            if(exBugSetupBindingSource.Current!=null)
            {
                ESRPDataSet.ExBugSetupRow setupr = ((DataRowView)exBugSetupBindingSource.Current).Row as ESRPDataSet.ExBugSetupRow;
                AnNUD.Value = setupr.AnulCurent;
                LunaCB.SelectedIndex = setupr.LunaCurenta - 1;
            }
            this.departamenteParametriiTableAdapter.Connection = con;
            this.departamenteParametriiTableAdapter.FillByLunaAn(this.eSRPDataSet.DepartamenteParametrii, ModuleInfo.CodUnitate,(short) AnNUD.Value,(short)( LunaCB.SelectedIndex+1));

            InchideConexiune(con);
            AddBindingSource(departamenteParametriiBindingSource);
            AddTableAdaptor(departamenteParametriiTableAdapter.Adapter);

        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            
        }

        

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            SqlCommand com = new SqlCommand("GenDepartamenteParam", con);
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.Add(new SqlParameter("@CodUnitate", ModuleInfo.CodUnitate));
            com.Parameters.Add(new SqlParameter("@An", AnNUD.Value));
            com.Parameters.Add(new SqlParameter("@Luna", LunaCB.SelectedIndex + 1));
            com.ExecuteNonQuery();
            this.departamenteParametriiTableAdapter.Connection = con;
            this.departamenteParametriiTableAdapter.Fill(this.eSRPDataSet.DepartamenteParametrii, ModuleInfo.CodUnitate);
            InchideConexiune(con);
        }
    }
}
